/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.laboratory;

import ejb.system.AbstractFacade;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ciummo
 */
@Stateless
public class ControlloFacade extends AbstractFacade<Controllo> implements ControlloFacadeRemote {
    @PersistenceContext(unitName = "DGestEJBSeverPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ControlloFacade() {
        super(Controllo.class);
    }
    
    
    public int deleteControlli(String codArticolo) {
        
        String sql = "DELETE FROM Controllo c WHERE c.codArticolo =:id";
        Query query = em.createQuery(sql);
        query.setParameter("id", codArticolo);
        int executeUpdate = query.executeUpdate();
        return executeUpdate;
    }
    
        public List<Controllo> findControlliBycodArticolo (String codArticolo){

        String sql = "SELECT c FROM Controllo c WHERE c.codArticolo = :codArticolo";
        Query query = em.createQuery(sql);
        query.setParameter("codArticolo", codArticolo);
        return query.getResultList();
    }  
    
        public List<String> findCodArticoloCheck (){

        String sql = "SELECT DISTINCT c.codArticolo FROM Controllo c";
        Query query = em.createQuery(sql);
        return query.getResultList();
    }  
        
}
